// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({
    env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database()
const _ = db.command
// 云函数入口函数
exports.main = async (event, context) => {
    const {asDate,pageSize,id} = event
    let params = {}
    if(asDate){
        params = Object.assign({},params,{newDateIdx:_.gte(asDate)})
    }
    if(id){
        params = {
            _id:_.eq(id)
        }
    }
    const result =  await db.collection('article').where(params).orderBy("newDateIdx","desc").skip(pageSize||0).limit(10).get()
    return {
        result
    }
}